// 7-4 一帮一
#include <stdio.h>

struct Stu {
    int  sex;
    int  selected;
    char name[9];
};

int main()
{
    int n;
    scanf("%d", &n);
    struct Stu s[n];
    for (int i=0; i<n; i++) {
        scanf("%d%s", &s[i].sex, s[i].name);
        s[i].selected = 0;
    }
    for (int i=0; i<n/2; i++) {
        printf("%s ", s[i].name);
        for (int j=n-1; j>=0; j--) {
            if (!s[j].selected && s[i].sex != s[j].sex) {
                s[j].selected = 1;
                printf("%s\n", s[j].name);
                break;
            }
        }
    }
    return 0;
}